<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bubbleSort </title>
</head>
<body>
    <script>
        function bubbleSort(arr) {
            for(var i = 0;i < Math.floor(arr.length/2);i++) {
                for(var j = 0;j < arr.length - i;j++) {
                    if(arr[j] > arr[j+1]) {
                        var tmp = arr[j];
                        arr[j] = arr[j+1];
                        arr[j+1] = tmp;
                    }
                }
            }
            return arr;
        }
        function binary_search(arr,x) {
            var left = 0
            var right = arr.length - 1
            while(left < right){
                var mid = parseInt((left + right) / 2)
                var num = arr[mid]
                if(num == x){
                    return mid
                }else if(num > x){
                    right = mid - 1
                }else{
                    left = mid + 1
                }
            }
            return -1
        }
        console.log(bubbleSort([1, 56, 2, 3, 88, 5, 2436, 6, 2, 43, 45, 4242, 16, 2, 87]));
        var arr  = [1,2,3,5,6,7,7,10]
        console.log(binary_search(arr,7));
        console.log(binary_search(arr,8)); 
    </script>
</body>
</html>